package com.feri.ssm.service.impl;

import com.feri.ssm.dao.UserDao;
import com.feri.ssm.entity.User;
import com.feri.ssm.service.intf.UserService;
import com.feri.ssm.vo.PageBean;
import com.feri.ssm.vo.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

/**
 * @author Feri
 * @date 2021/12/13 15:30
 * @description:TODO
 */
@Service //IOC创建类的对象
public class UserServiceImpl implements UserService {
    @Autowired//属性注入
    private UserDao dao;
//    @Autowired
//    private JdbcTemplate jdbcTemplate;


    @Override
    public R save(User user) {
        if(dao.insert(user)>0){
            System.err.println(1/0);
            dao.insert(user);
            return new R(200,"OK",null);
        }else{
            return new R(400,"新增用户失败",null);
        }
    }

    @Override
    public PageBean queryAll(int page, int limit) {
        PageHelper.startPage(page, limit);
        PageInfo<User> pageInfo=new PageInfo<>(dao.selectAll());
        return new PageBean(pageInfo.getTotal(),pageInfo.getList());
    }
    //原来的方式
    public R queryAll1() {
        long l1=System.currentTimeMillis();
        R r= new R(200,"OK",dao.selectAll());
        System.err.println(System.currentTimeMillis()-l1);
        return r;
    }
}
